< previous page page_114 next page >

Page 114
Local Variables
Lets first look at local variables that are declared at the top of a procedure. If you click several times on the Local button when the form is running, youll see that the value stays at 1. The code for this event procedure looks like this:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdLocal_Click ()
   Dim intCount As Integer

   intCount = intCount + 1

   lblLocal.Caption = intCount
End Sub
EXERCISE
Look at the Local Command Button
1. Return to design mode and load the VarExamples.frm file.
2. Double-click the Local command button to view the code.
analysis.gifIf you look at the code in this example the following paragraph will be a little easier to follow.
Each time the Local button is clicked, the Dim statement causes the intCount variable to be reinitialized to 0. Using an assignment statement, the intCount variable is incremented by 1 and then the result of this value is placed in the lblLocal labels Caption property. Once End Sub is executed, the value of intCount is released from memory.

Module Variables
If you declare a variable using Private or Dim in the (General) (Declarations) section of a module, that variable is visible to any procedure contained in that module. No procedures in other modules can view or change a module variable in another module. Prefacing the names of these variables with the letter m is a visual clue as to what the scope of the variables is (see Figure 6.3).
8160-0114a.gif
Figure 6.3
Example of a module-level variable.

 
< previous page page_114 next page >

If you like this book, buy it!